package zxing.activity.adapter;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;

import java.util.List;

import io.virtualapp.R;
import io.virtualapp.bean.ReplyBean;
import io.virtualapp.home.adapters.ImageSeeAdapter;
import zxing.activity.ImagesVIewActivity;

public class ReplyBeanAdapter extends BaseMultiItemQuickAdapter<ReplyBean, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ReplyBeanAdapter(List<ReplyBean> data) {
        super(data);
        addItemType(ReplyBean.LEFT, R.layout.su_item_reply_left_layout);
        addItemType(ReplyBean.RIGHT, R.layout.su_item_reply_right_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, ReplyBean item) {
        switch (item.getItemType()) {
            case ReplyBean.LEFT:
                helper.setText(R.id.tv_name,item.getStaff());
                break;
            case ReplyBean.RIGHT:
                helper.setText(R.id.tv_name,"我");
                break;
        }

        helper.setText(R.id.tv_context,item.getDescribe());

        if (item.getImg()!=null&&item.getImg().size()>0){
            helper.setGone(R.id.rc_img,true);
            GridLayoutManager manager = new GridLayoutManager(mContext,3);
            RecyclerView recyclerView = helper.getView(R.id.rc_img);
            recyclerView.setLayoutManager(manager);
            ImageSeeAdapter adapter = new ImageSeeAdapter(item.getImg());
            recyclerView.setAdapter(adapter);
            adapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    Intent intent = new Intent(mContext,ImagesVIewActivity.class);
                    intent.putExtra(ImagesVIewActivity.IMG_POS,position);
                    Gson gson = new Gson();
                    intent.putExtra(ImagesVIewActivity.IMG_DATAS, gson.toJson(adapter.getData()));
                    mContext.startActivity(intent);
                }
            });

        }else {
            helper.setGone(R.id.rc_img,false);
        }

    }
}
